/**
 * Created by python on 18-11-11.
 */
var aaa = new Vue({
    el:"#app",
    data:{
        // 页面中需要使用到的数据，键值对
        but1 : true,
        but2 : true,
        but3 : true,
        but4 : true,
        base ,
        info1 : true,
        info2 : true,
        info3 : true,
        info4 : true,
        info5 : true,
        user_id: sessionStorage.user_id || localStorage.user_id,
        token: sessionStorage.token || localStorage.token,
        username : "",
        school : "",
        city : "",
        company : "",
        eamil : "",
        password : "",
        mobile : "",
        personurl : "",
        introduction : "",

    },
    computed:{
        // 需要通过计算得到的数据，键值对 ，键是名称，值是匿名函数
    },
    mounted:function () {
        // 一加载就需要做的，直接是代码
        this.show_user_info()
    },
    methods:{
        
        // 需要用到的函数，键值对 ，键是名称，值是匿名函数
        show_user_info : function () {
            axios.get(this.base + '/userinfo/' + this.user_id + '/', {
               headers: {
                    'Authorization': 'JWT ' + this.token

                },
                responseType: 'json',
            })
                .then(response => {
                    // 加载用户数据
                    // console.log(response.data)

                    // this.user_id = response.data.id;
                    this.username = response.data.username;
                    this.city = response.data.city;
                    this.mobile = response.data.mobile;
                    this.email = response.data.email;
                    this.school = response.data.school;
                    this.password = response.data.password;
                    this.company = response.data.company;
                    this.personurl = response.data.personurl;
                    this.introduction = response.data.introduction;

                })
                .catch(error => {
                    alert(error)
                })
        },
        show_city : function () {
            this.but1 = false
        },
        show_sch : function () {
            this.but2 = false
        },
        show_com : function () {
            this.but3 = false
        },
        show_url : function () {
            this.but4 = false
        },
        change_username : function () {
            this.info1 = false
        },
        change_url : function () {
            this.info2 = false
        },
        change_email : function () {
            this.info3 = false
        },
        change_mobile : function () {
            this.info4 = false
        },
        change_password : function () {
            this.info5 = false
        },

        bing_wx : function () {
            location.href = '/bind_weixin.html'
        },


        all_submit : function () {

            axios.patch(this.base + '/userinfoupdate/' + this.user_id + '/', {

                    username : this.username,
                    city : this.city,
                    email : this.email,
                    personurl : this.personurl,
                    school : this.school,
                    company : this.company,
                    password : this.password,
                    mobile : this.mobile,
                    headers: {
                        'Authorization': 'JWT ' + this.token
                    },
                    responseType: 'json',
                    withCredentials: true
                })
               .then(response => {
                   this.show_user_info()
                   this.but1 = false;
                   this.but2 = false;
                   this.but3 = false;
                   this.but4 = false;
                   this.info1 = false;
                   this.info2 = false;
                   this.info3 = false;
                   this.info4 = false;
                   this.info5 = false;

               })
                .catch(

                )
        }




    }
})